package com.bee.plus.market.service;

import com.bee.plus.util.Conversation;
import com.bee.plus.util.ConversationThreadLocal;
import com.bee.plus.util.SnowIdUtil;
import com.bee.plus.vo.ChatMessageVo;
import com.bee.plus.vo.ChatResponseVo;
import io.reactivex.Flowable;


public class MarketAiServiceProxy implements MarketAiService{

    private final MarketAiService target;

    public MarketAiServiceProxy(MarketAiService target){
         this.target=target;
    }
    @Override
    public ChatResponseVo chat(ChatMessageVo messageVo) {
        Long conversationId=messageVo.getConversationId()==null? SnowIdUtil.getNextId(): messageVo.getConversationId();
        messageVo.setConversationId(conversationId);
        ConversationThreadLocal.addCurrentConversation(Conversation.builder().conversationId(conversationId).modelType(messageVo.getModelType()).build());

        return target.chat(messageVo);
    }

    @Override
    public Flowable<ChatResponseVo> chatStream(ChatMessageVo messageVo) {
        Long conversationId=messageVo.getConversationId()==null? SnowIdUtil.getNextId(): messageVo.getConversationId();
        messageVo.setConversationId(conversationId);
        ConversationThreadLocal.addCurrentConversation(Conversation.builder().conversationId(conversationId).modelType(messageVo.getModelType()).build());

        return target.chatStream(messageVo);
    }

    @Override
    public void storeChatMessage(ChatResponseVo responseVo) {
        target.storeChatMessage(responseVo);
    }
}
